#ifndef NIXONBOT_CORE_BNCS_PROTOCOL_AUTHCHECKSERVER_H_
#define NIXONBOT_CORE_BNCS_PROTOCOL_AUTHCHECKSERVER_H_

#include <nixonbot/core/bncs/protocol/Message.h>
#include <nixonbot/core/bncs/protocol/MessageFactory.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

struct AuthCheckServerData : public QSharedData
{
	quint32 result;
	QByteArray additionalInfo;
};

class AuthCheckServer : public Message
{
public:
	static const int id = 0x51;
	BNCS_MESSAGE_SERVER_REGISTER(AuthCheckServer, id);

public:
	QSharedDataPointer<AuthCheckServerData> d;

public:
	AuthCheckServer()
	{
		d = new AuthCheckServerData();
	}
	
	virtual AuthCheckServer* create()
	{
		return new AuthCheckServer();
	}
	
	virtual quint32 id()
	{
		return id;
	}

	virtual int size()
	{
		return sizeof(d->result) + (d->additionalInfo.size() + 1);
	}

protected:
	virtual void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds >> d->result;
		d->additionalInfo = readStringFrom(ds);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	virtual void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds << d->result;
		writeStringTo(ds, d->additionalInfo);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

}
}
}
}


#endif /* NIXONBOT_CORE_BNCS_PROTOCOL_AUTHCHECKSERVER_H_ */
